<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<c:set var="isMonitor" value="${roleCode eq 'crest'?'true':'false'}" />
<html>
<head>
	<title>用户管理</title>
	<%@include file="/WEB-INF/views/include/head.jsp" %>
	<script type="text/javascript">
		var myvalidate;
		$(document).ready(function() {
			var height=$(window).height()-70;
			$('#myUserForm').height(height);
			myvalidate=$("#inputForm").validate({
				rules: {
					loginName: {remote: "${ctxAdmin}/sys/user/checkLoginName?oldLoginName=" + encodeURIComponent('${user.loginName}')}
				},
				messages: {
					loginName: {remote: "用户登录名已存在"},
					confirmNewPassword: {equalTo: "输入与上面相同的密码"}
				},
				submitHandler: function(form){
					layer.msg('正在提交，请稍等...',{icon:16});
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$(element).closest( "form" )
					.find( "span[for='" + element.attr( "name" ) + "']" ).html(error);
					var type=$(element).attr('type');
					if(type=='checkbox'||type=='radio'||type=='select')$(error).text("必选项");
				}
			});
		});
		
		
	</script>

</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctxAdmin}/sys/user/list">用户列表</a></li>
		<li class="active"><a href="${ctxAdmin}/sys/user/form?id=${user.id}"><shiro:hasPermission name="sys:user:edit">${not empty user.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:user:edit">查看</shiro:lacksPermission>用户</a></li>
	</ul>
	<div id="myUserForm" style="overflow-y:auto;overflow-x: hidden; ">
		<form:form id="inputForm" modelAttribute="user" action="${ctxAdmin}/sys/user/save" method="post" class="form-horizontal">
			<form:hidden path="id"/>
			<sys:message content="${message}"/>
		
			<div class="form-group">
				<label class="col-sm-3 control-label">所属机构:</label>
				<div class="col-sm-5">
	                <sys:treeselect id="office" name="office.id" value="${user.office.id}" disabled="${isMonitor}" labelName="office.name" labelValue="${user.office.name}"
						title="所属机构" url="/sys/office/treeData"  cssClass="required" notAllowSelectRoot="true"/>
				</div>
				<div class="col-sm-2">
					<span for="office.name"></span>
					<font color="red">*</font>
				</div>
			</div>
			<div class="hr-line-dashed"></div>

			<div class="form-group">
				<label class="col-sm-3 control-label">用户名称:</label>
				<div class="col-sm-5">
					<form:input path="name" htmlEscape="false" maxlength="50" class="required form-control"/>
				</div>
				<div class="col-sm-2">
					<span for="name"></span>
					<font color="red">*</font>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">登录名:</label>
				<div class="col-sm-5">
					<input id="oldLoginName" name="oldLoginName" type="hidden" value="${user.loginName}"/>
					<form:input path="loginName" htmlEscape="false" maxlength="50" class="required userName form-control"/>
				</div>
				<div class="col-sm-2">
					<span for="loginName"></span>
					<font color="red">*</font>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">密码:</label>
				<div class="col-sm-5">
					<input id="newPassword" name="newPassword" type="password" value="" maxlength="16" minlength="6" class="${empty user.id?'required':''} form-control"/>
					<c:if test="${not empty user.id}"><span class="help-block m-b-none">若不修改密码，请留空。</span></c:if>
				</div>
				<c:if test="${empty user.id}">
				<div class="col-sm-2">
					<span for="newPassword"></span>
					<font color="red">*</font>
				</div>
				</c:if>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">确认密码:</label>
				<div class="col-sm-5">
					<input id="confirmNewPassword" name="confirmNewPassword" class="${empty user.id?'required':''} form-control" type="password" value="" maxlength="50" minlength="3" equalTo="#newPassword"/>
				</div>
				<c:if test="${empty user.id}">
				<div class="col-sm-2">
					<span for="confirmNewPassword"></span>
					<font color="red">*</font>
				</div>
				</c:if>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">邮箱:</label>
				<div class="col-sm-5">
					<form:input path="email" htmlEscape="false" maxlength="100" class="email form-control"/>
				</div>
				<div class="col-sm-2">
					<span for="email"></span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">电话:</label>
				<div class="col-sm-5">
					<form:input path="phone" htmlEscape="false" maxlength="100" cssClass="phoneCN form-control"/>
				</div>
				<div class="col-sm-2">
					<span for="phone"></span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">手机:</label>
				<div class="col-sm-5">
					<form:input path="mobile" htmlEscape="false" maxlength="100" cssClass="mobileCN form-control"/>
				</div>
				<div class="col-sm-2">
					<span for="mobile"></span>
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="form-group">
				<label class="col-sm-3 control-label">是否允许登录:</label>

				<div class="col-sm-5">
							
					<form:select path="loginFlag" cssStyle="width: 120px" class="form-control m-b">
						<form:options items="${loginFlagList}" itemLabel="label" itemValue="value" htmlEscape="false"/>
					</form:select>
										
<!-- 					<span class="help-block m-b-none">“是”代表此账号允许登录，“否”则表示此账号不允许登录</span> -->
				</div>
				
			</div>
			<div class="form-group">

				<label class="col-sm-3 control-label">是否超管:</label>
				<div class="col-sm-5">
					<form:select path="adminFlag" cssStyle="width: 120px" class="form-control m-b">
						<form:options items="${adminFlagList}" itemLabel="label" itemValue="value" htmlEscape="false"/>
					</form:select>
				</div>
								
				
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">用户角色:</label>
				<div class="col-sm-5">
					<c:forEach items="${allRoles}" var="role">
						<div class="checkbox checkbox-inline">
							<form:checkbox path="roleIdList" cssClass="required" value="${role.id}" label="${role.name}" htmlEscape="false"/>
						</div>
					</c:forEach>
				</div>
				<div class="col-sm-2">
					<span for="roleIdList"></span>
					<font color="red">*</font>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">备注:</label>
				<div class="col-sm-5">
					<form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="form-control"/>
				</div>
			</div>
			<c:if test="${not empty user.id}">
				<div class="form-group">
					<label class="col-sm-3 control-label">创建时间:</label>
					<div class="col-sm-5">
						<label class="lbl"><fmt:formatDate value="${user.createDate}" type="both" dateStyle="full"/></label>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">最后登陆:</label>
					<div class="col-sm-5">
						<label class="lbl">IP: ${user.loginIp}&nbsp;&nbsp;&nbsp;&nbsp;时间：<fmt:formatDate value="${user.loginDate}" type="both" dateStyle="full"/></label>
					</div>
				</div>
			</c:if>
			<div class="form-group">
				<div class="col-sm-5 col-sm-offset-3">
				<shiro:hasPermission name="sys:user:edit"><input id="btnSubmit" class="btn btn-success btn-sm" type="submit" value="保 存" />&nbsp;</shiro:hasPermission>
				<input id="btnCancel" class="btn btn-default btn-sm" type="button" value="返 回" onclick="history.go(-1)"/>
				</div>
			</div>
		</form:form>
	</div>
</body>
</html>